
{% if elasticsearch_conf %}
{{ elasticsearch_conf | to_nice_yaml(indent=2) }}
{% endif %}

{% if elasticsearch_conf['cluster.name'] is not defined %}
cluster.name: es-cluster
{% endif %}

{% if elasticsearch_conf['node.name'] is not defined %}
node.name: {{ ansible_hostname | d(inventory_hostname) }}
{% endif %}

{% if elasticsearch_conf['network.host'] is not defined %}
network.host: {{ elasticsearch_http_host | default('localhost') }}
{% endif %}

{% if elasticsearch_conf['http.port'] is not defined %}
http.port: {{ elasticsearch_http_port | default('9200') }}
{% endif %}

{% if elasticsearch_conf['path.data'] is not defined %}
path.data:
{{ elasticsearch_data_paths | to_nice_yaml(indent=2) }}
{% endif %}

{% if elasticsearch_conf['path.logs'] is not defined %}
path.logs: {{ elasticsearch_log_path }}
{% endif %}

{% if elasticsearch_conf['discovery.seed_hosts'] is not defined %}
discovery.seed_hosts: ["127.0.0.1"]
{% endif %}

{% if elasticsearch_conf['cluster.initial_master_nodes'] is not defined %}
cluster.initial_master_nodes: ["{{ elasticsearch_conf['node.name'] | d(ansible_hostname) | d(inventory_hostname) }}"]
{% endif %}


{% if elasticsearch_xpack_enable | bool %}
xpack.security.enabled: true
xpack.security.audit.enabled: true

{% if elasticsearch_enable_transport_ssl | bool %}
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: "{{ elasticsearch_ssl_verification_mode }}"
{% if elasticsearch_ssl_keystore and elasticsearch_ssl_truststore %}
xpack.security.transport.ssl.keystore.path: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_keystore | basename }}"
xpack.security.transport.ssl.truststore.path: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_truststore | basename }}"
{% elif elasticsearch_ssl_key and  elasticsearch_ssl_certificate %}
xpack.security.transport.ssl.key: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_key | basename }}"
xpack.security.transport.ssl.certificate: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_certificate | basename }}"
{% if elasticsearch_ssl_certificate_authority %}
xpack.security.transport.ssl.certificate_authorities: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_certificate_authority | basename }}"
{% endif %}
{% endif %}
{% endif %}

{% if elasticsearch_enable_http_ssl | bool %}
xpack.security.http.ssl.enabled: true
{% if elasticsearch_ssl_keystore and elasticsearch_ssl_truststore %}
xpack.security.http.ssl.keystore.path: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_keystore | basename }}"
xpack.security.http.ssl.truststore.path: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_truststore | basename }}"
{% elif elasticsearch_ssl_key and  elasticsearch_ssl_certificate %}
xpack.security.http.ssl.key: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_key | basename }}"
xpack.security.http.ssl.certificate: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_certificate | basename }}"
{% if elasticsearch_ssl_certificate_authority %}
xpack.security.http.ssl.certificate_authorities: "{{ elasticsearch_ssl_certificate_path }}/{{ elasticsearch_ssl_certificate_authority | basename }}"
{% endif %}
{% endif %}
{% endif %}
{% endif %}


{% if elasticsearch_mail_config is defined %}
xpack.notification.email:
  account:
    {{ elasticsearch_mail_config['account'] }}:
      profile: {{ elasticsearch_mail_config['profile'] }}
      email_defaults:
        from: {{ elasticsearch_mail_config['from'] }}
      smtp:
        auth: {{ elasticsearch_mail_config['require_auth'] }}
        host: {{ elasticsearch_mail_config['host'] }}
        port: {{ elasticsearch_mail_config['port'] }}
        {% if elasticsearch_mail_config['require_auth'] == true -%}
        user: {{ elasticsearch_mail_config['user'] }}
        password: {{ elasticsearch_mail_config['pass'] }}
        {%- endif %}
{% endif %}
